home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume10 / ptoc / part07 < prev    next >
Encoding:
Internet Message Format  |  1987-07-27  |  41.9 KB

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v10i071:  Pascal to C translator, Part07/12
  5. Message-ID: <722@uunet.UU.NET>
  6. Date: 28 Jul 87 19:35:56 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 1546
  9. Approved: rs@uunet.UU.NET
  10.  
  11. Submitted-by: Per Bergsten <mcvax!enea!chalmers!holtec!perb>
  12. Posting-number: Volume 10, Issue 71
  13. Archive-name: ptoc/Part07
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 7 (of 12)."
  22. # Contents:  ptc.c.5
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'ptc.c.5' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'ptc.c.5'\"
  26. else
  27. echo shar: Extracting \"'ptc.c.5'\" \(39665 characters\)
  28. sed "s/^X//" >'ptc.c.5' <<'END_OF_FILE'
  29. X void
  30. Xeexpr(tp)
  31. X    treeptr    tp;
  32. X{
  33. X    treeptr    tq;
  34. X    boolean    flag;
  35. X
  36. X    (*G200_donearr) = false;
  37. X    if (Member((unsigned)(tp->tt), Conset[144])) {
  38. X        tq = typeof(tp->U.V41.texpl);
  39. X        if ((Member((unsigned)(tq->tt), Conset[145])) || (tq == typnods.A[(int)(tset)])) {
  40. X            switch (tp->tt) {
  41. X              case nplus:
  42. X                (*G196_setused) = true;
  43. X                useunion = true;
  44. X                (void)fprintf(output.fp, "Union"), Putl(output, 0);
  45. X                break ;
  46. X              case nminus:
  47. X                (*G196_setused) = true;
  48. X                usediff = true;
  49. X                (void)fprintf(output.fp, "Diff"), Putl(output, 0);
  50. X                break ;
  51. X              case nmul:
  52. X                (*G196_setused) = true;
  53. X                useintr = true;
  54. X                (void)fprintf(output.fp, "Inter"), Putl(output, 0);
  55. X                break ;
  56. X              case neq:
  57. X                useseq = true;
  58. X                (void)fprintf(output.fp, "Eq"), Putl(output, 0);
  59. X                break ;
  60. X              case nne:
  61. X                usesne = true;
  62. X                (void)fprintf(output.fp, "Ne"), Putl(output, 0);
  63. X                break ;
  64. X              case nge:
  65. X                usesge = true;
  66. X                (void)fprintf(output.fp, "Ge"), Putl(output, 0);
  67. X                break ;
  68. X              case nle:
  69. X                usesle = true;
  70. X                (void)fprintf(output.fp, "Le"), Putl(output, 0);
  71. X                break ;
  72. X              default:
  73. X                Caseerror(Line);
  74. X            }
  75. X            if (Member((unsigned)(tp->tt), Conset[146]))
  76. X                (*G198_dropset) = false;
  77. X            Putchr('(', output);
  78. X            eexpr(tp->U.V41.texpl);
  79. X            if (tq->tt == nsetof)
  80. X                (void)fprintf(output.fp, ".S"), Putl(output, 0);
  81. X            (void)fprintf(output.fp, ", "), Putl(output, 0);
  82. X            eexpr(tp->U.V41.texpr);
  83. X            tq = typeof(tp->U.V41.texpr);
  84. X            if (tq->tt == nsetof)
  85. X                (void)fprintf(output.fp, ".S"), Putl(output, 0);
  86. X            Putchr(')', output);
  87. X            goto L999;
  88. X        }
  89. X    }
  90. X    if (Member((unsigned)(tp->tt), Conset[147])) {
  91. X        tq = typeof(tp->U.V41.texpl);
  92. X        if (tq->tt == nconfarr)
  93. X            fatal(ecmpconf);
  94. X        if ((Member((unsigned)(tq->tt), Conset[148])) || (tq == typnods.A[(int)(tstring)])) {
  95. X            (void)fprintf(output.fp, "Cmpstr("), Putl(output, 0);
  96. X            eexpr(tp->U.V41.texpl);
  97. X            if (tq->tt == narray)
  98. X                (void)fprintf(output.fp, ".A"), Putl(output, 0);
  99. X            (void)fprintf(output.fp, ", "), Putl(output, 0);
  100. X            tq = typeof(tp->U.V41.texpr);
  101. X            if (tq->tt == nconfarr)
  102. X                fatal(ecmpconf);
  103. X            eexpr(tp->U.V41.texpr);
  104. X            if (tq->tt == narray)
  105. X                (void)fprintf(output.fp, ".A"), Putl(output, 0);
  106. X            Putchr(')', output);
  107. X            switch (tp->tt) {
  108. X              case neq:
  109. X                (void)fprintf(output.fp, " == "), Putl(output, 0);
  110. X                break ;
  111. X              case nne:
  112. X                (void)fprintf(output.fp, " != "), Putl(output, 0);
  113. X                break ;
  114. X              case ngt:
  115. X                (void)fprintf(output.fp, " > "), Putl(output, 0);
  116. X                break ;
  117. X              case nlt:
  118. X                (void)fprintf(output.fp, " < "), Putl(output, 0);
  119. X                break ;
  120. X              case nge:
  121. X                (void)fprintf(output.fp, " >= "), Putl(output, 0);
  122. X                break ;
  123. X              case nle:
  124. X                (void)fprintf(output.fp, " <= "), Putl(output, 0);
  125. X                break ;
  126. X              default:
  127. X                Caseerror(Line);
  128. X            }
  129. X            Putchr('0', output);
  130. X            goto L999;
  131. X        }
  132. X    }
  133. X    switch (tp->tt) {
  134. X      case neq:  case nne:  case nlt:  case nle:
  135. X      case ngt:  case nge:  case nor:  case nand:
  136. X      case nplus:  case nminus:  case nmul:  case ndiv:
  137. X      case nmod:  case nquot:
  138. X        flag = (boolean)(cprio.A[(int)(tp->tt) - (int)(nassign)] > cprio.A[(int)(tp->U.V41.texpl->tt) - (int)(nassign)]);
  139. X        if ((Member((unsigned)(tp->tt), Conset[149])) && !arithexpr(tp->U.V41.texpl)) {
  140. X            (void)fprintf(output.fp, "(int)"), Putl(output, 0);
  141. X            flag = true;
  142. X        }
  143. X        if (flag)
  144. X            Putchr('(', output);
  145. X        eexpr(tp->U.V41.texpl);
  146. X        if (flag)
  147. X            Putchr(')', output);
  148. X        switch (tp->tt) {
  149. X          case neq:
  150. X            (void)fprintf(output.fp, " == "), Putl(output, 0);
  151. X            break ;
  152. X          case nne:
  153. X            (void)fprintf(output.fp, " != "), Putl(output, 0);
  154. X            break ;
  155. X          case nlt:
  156. X            (void)fprintf(output.fp, " < "), Putl(output, 0);
  157. X            break ;
  158. X          case nle:
  159. X            (void)fprintf(output.fp, " <= "), Putl(output, 0);
  160. X            break ;
  161. X          case ngt:
  162. X            (void)fprintf(output.fp, " > "), Putl(output, 0);
  163. X            break ;
  164. X          case nge:
  165. X            (void)fprintf(output.fp, " >= "), Putl(output, 0);
  166. X            break ;
  167. X          case nor:
  168. X            (void)fprintf(output.fp, " || "), Putl(output, 0);
  169. X            break ;
  170. X          case nand:
  171. X            (void)fprintf(output.fp, " && "), Putl(output, 0);
  172. X            break ;
  173. X          case nplus:
  174. X            (void)fprintf(output.fp, " + "), Putl(output, 0);
  175. X            break ;
  176. X          case nminus:
  177. X            (void)fprintf(output.fp, " - "), Putl(output, 0);
  178. X            break ;
  179. X          case nmul:
  180. X            (void)fprintf(output.fp, " * "), Putl(output, 0);
  181. X            break ;
  182. X          case ndiv:
  183. X            (void)fprintf(output.fp, " / "), Putl(output, 0);
  184. X            break ;
  185. X          case nmod:
  186. X            (void)fprintf(output.fp, " %% "), Putl(output, 0);
  187. X            break ;
  188. X          case nquot:
  189. X            (void)fprintf(output.fp, " / (("), Putl(output, 0);
  190. X            printid(defnams.A[(int)(dreal)]->U.V6.lid);
  191. X            Putchr(')', output);
  192. X            break ;
  193. X          default:
  194. X            Caseerror(Line);
  195. X        }
  196. X        flag = (boolean)(cprio.A[(int)(tp->tt) - (int)(nassign)] > cprio.A[(int)(tp->U.V41.texpr->tt) - (int)(nassign)]);
  197. X        if ((Member((unsigned)(tp->tt), Conset[150])) && !arithexpr(tp->U.V41.texpr)) {
  198. X            (void)fprintf(output.fp, "(int)"), Putl(output, 0);
  199. X            flag = true;
  200. X        }
  201. X        if (flag)
  202. X            Putchr('(', output);
  203. X        eexpr(tp->U.V41.texpr);
  204. X        if (flag)
  205. X            Putchr(')', output);
  206. X        if (tp->tt == nquot)
  207. X            Putchr(')', output);
  208. X        break ;
  209. X      case nuplus:  case numinus:  case nnot:
  210. X        switch (tp->tt) {
  211. X          case numinus:
  212. X            Putchr('-', output);
  213. X            break ;
  214. X          case nnot:
  215. X            Putchr('!', output);
  216. X            break ;
  217. X          case nuplus:
  218. X            break ;
  219. X          default:
  220. X            Caseerror(Line);
  221. X        }
  222. X        flag = (boolean)(cprio.A[(int)(tp->tt) - (int)(nassign)] >= cprio.A[(int)(tp->U.V42.texps->tt) - (int)(nassign)]);
  223. X        if (flag)
  224. X            Putchr('(', output);
  225. X        eexpr(tp->U.V42.texps);
  226. X        if (flag)
  227. X            Putchr(')', output);
  228. X        break ;
  229. X      case nin:
  230. X        usememb = true;
  231. X        (void)fprintf(output.fp, "Member((unsigned)("), Putl(output, 0);
  232. X        eexpr(tp->U.V41.texpl);
  233. X        (void)fprintf(output.fp, "), "), Putl(output, 0);
  234. X        (*G198_dropset) = true;
  235. X        eexpr(tp->U.V41.texpr);
  236. X        (*G198_dropset) = false;
  237. X        tq = typeof(tp->U.V41.texpr);
  238. X        if (tq->tt == nsetof)
  239. X            (void)fprintf(output.fp, ".S"), Putl(output, 0);
  240. X        Putchr(')', output);
  241. X        break ;
  242. X      case nassign:
  243. X        tq = typeof(tp->U.V27.trhs);
  244. X        if (tq == typnods.A[(int)(tstring)]) {
  245. X            (void)fprintf(output.fp, "%sstrncpy(", voidcast), Putl(output, 0);
  246. X            eexpr(tp->U.V27.tlhs);
  247. X            (void)fprintf(output.fp, ".A, "), Putl(output, 0);
  248. X            eexpr(tp->U.V27.trhs);
  249. X            (void)fprintf(output.fp, ", sizeof("), Putl(output, 0);
  250. X            eexpr(tp->U.V27.tlhs);
  251. X            (void)fprintf(output.fp, ".A))"), Putl(output, 0);
  252. X        } else
  253. X            if (tq == typnods.A[(int)(tboolean)]) {
  254. X                eexpr(tp->U.V27.tlhs);
  255. X                (void)fprintf(output.fp, " = "), Putl(output, 0);
  256. X                tq = tp->U.V27.trhs;
  257. X                while (tq->tt == nuplus)
  258. X                    tq = tq->U.V42.texps;
  259. X                if (Member((unsigned)(tq->tt), Conset[151])) {
  260. X                    Putchr('(', output);
  261. X                    printid(defnams.A[(int)(dboolean)]->U.V6.lid);
  262. X                    (void)fprintf(output.fp, ")("), Putl(output, 0);
  263. X                    eexpr(tq);
  264. X                    Putchr(')', output);
  265. X                } else
  266. X                    eexpr(tq);
  267. X            } else
  268. X                if (tq == typnods.A[(int)(tnil)]) {
  269. X                    eexpr(tp->U.V27.tlhs);
  270. X                    (void)fprintf(output.fp, " = ("), Putl(output, 0);
  271. X                    etypedef(typeof(tp->U.V27.tlhs));
  272. X                    (void)fprintf(output.fp, ")NIL"), Putl(output, 0);
  273. X                } else {
  274. X                    tq = typeof(tp->U.V27.tlhs);
  275. X                    if (tq->tt == nsetof) {
  276. X                        usescpy = true;
  277. X                        (void)fprintf(output.fp, "Setncpy("), Putl(output, 0);
  278. X                        eselect(tp->U.V27.tlhs);
  279. X                        (void)fprintf(output.fp, "S, "), Putl(output, 0);
  280. X                        (*G198_dropset) = true;
  281. X                        tq = typeof(tp->U.V27.trhs);
  282. X                        if (tq == typnods.A[(int)(tset)])
  283. X                            eexpr(tp->U.V27.trhs);
  284. X                        else {
  285. X                            eselect(tp->U.V27.trhs);
  286. X                            Putchr('S', output);
  287. X                        }
  288. X                        (*G198_dropset) = false;
  289. X                        (void)fprintf(output.fp, ", sizeof("), Putl(output, 0);
  290. X                        eselect(tp->U.V27.tlhs);
  291. X                        (void)fprintf(output.fp, "S))"), Putl(output, 0);
  292. X                    } else {
  293. X                        eexpr(tp->U.V27.tlhs);
  294. X                        (void)fprintf(output.fp, " = "), Putl(output, 0);
  295. X                        eexpr(tp->U.V27.trhs);
  296. X                    }
  297. X                }
  298. X        break ;
  299. X      case ncall:
  300. X        tq = idup(tp->U.V30.tcall);
  301. X        if ((Member((unsigned)(tq->tt), Conset[152])) && (tq->U.V13.tsubstmt != (struct S61 *)NIL))
  302. X            if (tq->U.V13.tsubstmt->tt == npredef)
  303. X                epredef(tq, tp);
  304. X            else
  305. X                ecall(tp);
  306. X        else
  307. X            ecall(tp);
  308. X        break ;
  309. X      case nselect:
  310. X        eselect(tp->U.V40.trecord);
  311. X        eexpr(tp->U.V40.tfield);
  312. X        break ;
  313. X      case nindex:
  314. X        eselect(tp->U.V39.tvariable);
  315. X        (void)fprintf(output.fp, "A["), Putl(output, 0);
  316. X        tq = tp->U.V39.toffset;
  317. X        if (arithexpr(tq))
  318. X            eexpr(tq);
  319. X        else {
  320. X            (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  321. X            eexpr(tq);
  322. X            Putchr(')', output);
  323. X        }
  324. X        tq = typeof(tp->U.V39.tvariable);
  325. X        if (tq->tt == narray)
  326. X            if (clower(tq->U.V23.taindx) != 0) {
  327. X                (void)fprintf(output.fp, " - "), Putl(output, 0);
  328. X                tq = typeof(tq->U.V23.taindx);
  329. X                if (tq->tt == nsubrange)
  330. X                    if (arithexpr(tq->U.V19.tlo))
  331. X                        eexpr(tq->U.V19.tlo);
  332. X                    else {
  333. X                        (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  334. X                        eexpr(tq->U.V19.tlo);
  335. X                        Putchr(')', output);
  336. X                    }
  337. X                else
  338. X                    fatal(etree);
  339. X            }
  340. X        Putchr(']', output);
  341. X        break ;
  342. X      case nderef:
  343. X        tq = typeof(tp->U.V42.texps);
  344. X        if ((tq->tt == nfileof) || ((tq->tt == npredef) && (tq->U.V12.tdef == dtext))) {
  345. X            eexpr(tp->U.V42.texps);
  346. X            (void)fprintf(output.fp, ".buf"), Putl(output, 0);
  347. X        } else
  348. X            if ((*G202_doarrow) == 0) {
  349. X                Putchr('*', output);
  350. X                eexpr(tp->U.V42.texps);
  351. X            } else {
  352. X                eexpr(tp->U.V42.texps);
  353. X                (void)fprintf(output.fp, "->"), Putl(output, 0);
  354. X                (*G200_donearr) = true;
  355. X            }
  356. X        break ;
  357. X      case nid:
  358. X        tq = idup(tp);
  359. X        if (tq->tt == nvarpar) {
  360. X            if (((*G202_doarrow) == 0) || (tq->U.V14.tattr == areference)) {
  361. X                (void)fprintf(output.fp, "(*"), Putl(output, 0);
  362. X                printid(tp->U.V43.tsym->U.V6.lid);
  363. X                Putchr(')', output);
  364. X            } else {
  365. X                printid(tp->U.V43.tsym->U.V6.lid);
  366. X                (void)fprintf(output.fp, "->"), Putl(output, 0);
  367. X                (*G200_donearr) = true;
  368. X            }
  369. X        } else
  370. X            if ((tq->tt == nconst) && (*G194_conflag))
  371. X                (void)fprintf(output.fp, "%1d", cvalof(tp)), Putl(output, 0);
  372. X            else
  373. X                if (Member((unsigned)(tq->tt), Conset[153])) {
  374. X                    (void)fprintf(output.fp, "(*"), Putl(output, 0);
  375. X                    printid(tp->U.V43.tsym->U.V6.lid);
  376. X                    Putchr(')', output);
  377. X                } else
  378. X                    printid(tp->U.V43.tsym->U.V6.lid);
  379. X        break ;
  380. X      case nchar:
  381. X        printchr(tp->U.V43.tsym->U.V11.lchar);
  382. X        break ;
  383. X      case ninteger:
  384. X        (void)fprintf(output.fp, "%1d", tp->U.V43.tsym->U.V10.linum), Putl(output, 0);
  385. X        break ;
  386. X      case nreal:
  387. X        printtok(tp->U.V43.tsym->U.V8.lfloat);
  388. X        break ;
  389. X      case nstring:
  390. X        printstr(tp->U.V43.tsym->U.V7.lstr);
  391. X        break ;
  392. X      case nset:
  393. X        if (constset(tp->U.V42.texps)) {
  394. X            (void)fprintf(output.fp, "Conset[%1d]", setcnt), Putl(output, 0);
  395. X            setcnt = setcnt + 1;
  396. X            tq = mknode(nset);
  397. X            tq->tnext = setlst;
  398. X            setlst = tq;
  399. X            tq->U.V42.texps = tp->U.V42.texps;
  400. X        } else {
  401. X            increment();
  402. X            flag = (*G198_dropset);
  403. X            if ((*G198_dropset))
  404. X                (*G198_dropset) = false;
  405. X            else
  406. X                (void)fprintf(output.fp, "Saveset("), Putl(output, 0);
  407. X            (void)fprintf(output.fp, "(Tmpset = Newset(), "), Putl(output, 0);
  408. X            tq = tp->U.V42.texps;
  409. X            while (tq != (struct S61 *)NIL) {
  410. X                switch (tq->tt) {
  411. X                  case nrange:
  412. X                    usemksub = true;
  413. X                    (void)fprintf(output.fp, "%sMksubr(", voidcast), Putl(output, 0);
  414. X                    (void)fprintf(output.fp, "(unsigned)("), Putl(output, 0);
  415. X                    eexpr(tq->U.V41.texpl);
  416. X                    (void)fprintf(output.fp, "), "), Putl(output, 0);
  417. X                    (void)fprintf(output.fp, "(unsigned)("), Putl(output, 0);
  418. X                    eexpr(tq->U.V41.texpr);
  419. X                    (void)fprintf(output.fp, "), Tmpset)"), Putl(output, 0);
  420. X                    break ;
  421. X                  case nin:  case neq:  case nne:  case nlt:
  422. X                  case nle:  case ngt:  case nge:  case nor:
  423. X                  case nand:  case nmul:  case ndiv:  case nmod:
  424. X                  case nquot:  case nplus:  case nminus:  case nnot:
  425. X                  case numinus:  case nuplus:  case nindex:  case nselect:
  426. X                  case nderef:  case ncall:  case ninteger:  case nchar:
  427. X                  case nid:
  428. X                    useins = true;
  429. X                    (void)fprintf(output.fp, "%sInsmem(", voidcast), Putl(output, 0);
  430. X                    (void)fprintf(output.fp, "(unsigned)("), Putl(output, 0);
  431. X                    eexpr(tq);
  432. X                    (void)fprintf(output.fp, "), Tmpset)"), Putl(output, 0);
  433. X                    break ;
  434. X                  default:
  435. X                    Caseerror(Line);
  436. X                }
  437. X                tq = tq->tnext;
  438. X                if (tq != (struct S61 *)NIL) {
  439. X                    Putchr(',', output),Putchr('\n', output);
  440. X                    indent();
  441. X                }
  442. X            }
  443. X            (void)fprintf(output.fp, ", Tmpset)"), Putl(output, 0);
  444. X            if (!flag) {
  445. X                Putchr(')', output);
  446. X                (*G196_setused) = true;
  447. X            }
  448. X            decrement();
  449. X        }
  450. X        break ;
  451. X      case nnil:
  452. X        tq = tp;
  453. X        do {
  454. X            tq = tq->tup;
  455. X        } while (!(Member((unsigned)(tq->tt), Conset[154])));
  456. X        if (Member((unsigned)(tq->tt), Conset[155])) {
  457. X            if (typeof(tq->U.V41.texpl) == typnods.A[(int)(tnil)])
  458. X                tq = typeof(tq->U.V41.texpr);
  459. X            else
  460. X                tq = typeof(tq->U.V41.texpl);
  461. X            if (tq->tt == nptr) {
  462. X                Putchr('(', output);
  463. X                etypedef(tq);
  464. X                Putchr(')', output);
  465. X            }
  466. X        }
  467. X        (void)fprintf(output.fp, "NIL"), Putl(output, 0);
  468. X        break ;
  469. X      default:
  470. X        Caseerror(Line);
  471. X    }
  472. XL999:
  473. X    ;
  474. X}
  475. X
  476. X void
  477. Xeconst(tp)
  478. X    treeptr    tp;
  479. X{
  480. X    symptr    sp;
  481. X
  482. X    while (tp != (struct S61 *)NIL) {
  483. X        sp = tp->U.V14.tidl->U.V43.tsym;
  484. X        if (sp->U.V6.lid->inref > 1)
  485. X            sp->U.V6.lid = mkrename('X', sp->U.V6.lid);
  486. X        if (tp->U.V14.tbind->tt == nstring) {
  487. X            indent();
  488. X            (void)fprintf(output.fp, "%s%s%c", C50_static, chartyp, tab1), Putl(output, 0);
  489. X            printid(sp->U.V6.lid);
  490. X            (void)fprintf(output.fp, "[]    = "), Putl(output, 0);
  491. X            eexpr(tp->U.V14.tbind);
  492. X            Putchr(';', output),Putchr('\n', output);
  493. X        } else {
  494. X            (void)fprintf(output.fp, "%s", C4_define), Putl(output, 0);
  495. X            printid(sp->U.V6.lid);
  496. X            Putchr(space, output);
  497. X            eexpr(tp->U.V14.tbind);
  498. X            Putchr('\n', output);
  499. X        }
  500. X        tp = tp->tnext;
  501. X    }
  502. X}
  503. X
  504. Xvoid etypedef();
  505. X
  506. Xvoid etdef();
  507. X
  508. X void
  509. Xetrange(tp)
  510. X    treeptr    tp;
  511. X{
  512. X    integer    lo, hi;
  513. X    register unsigned char    i;
  514. X
  515. X    lo = clower(tp);
  516. X    hi = cupper(tp);
  517. X    {
  518. X        unsigned char    B51 = 1,
  519. X            B52 = nmachdefs;
  520. X
  521. X        if (B51 <= B52)
  522. X            for (i = B51; ; i++) {
  523. X                {
  524. X                    register struct S193 *W53 = &machdefs.A[i - 1];
  525. X
  526. X                    if ((lo >= W53->lolim) && (hi <= W53->hilim)) {
  527. X                        printtok(W53->typstr);
  528. X                        goto L999;
  529. X                    }
  530. X                }
  531. X                if (i == B52) break;
  532. X            }
  533. X    }
  534. X    fatal(erange);
  535. XL999:
  536. X    ;
  537. X}
  538. X
  539. X void
  540. Xprintsuf(ip)
  541. X    idptr    ip;
  542. X{
  543. X    toknbuf    w;
  544. X    toknidx    i, j;
  545. X
  546. X    gettokn(ip->istr, &w);
  547. X    i = 1;
  548. X    j = i;
  549. X    while (w.A[i - 1] != null) {
  550. X        if (w.A[i - 1] == '.')
  551. X            j = i;
  552. X        i = i + 1;
  553. X    }
  554. X    if (w.A[j - 1] == '.')
  555. X        j = j + 1;
  556. X    while (w.A[j - 1] != null) {
  557. X        Putchr(w.A[j - 1], output);
  558. X        j = j + 1;
  559. X    }
  560. X}
  561. X
  562. X void
  563. Xetdef(uid, tp)
  564. X    idptr    uid;
  565. X    treeptr    tp;
  566. X{
  567. X    integer    i;
  568. X    treeptr    tq;
  569. X
  570. X    switch (tp->tt) {
  571. X      case nid:
  572. X        printid(tp->U.V43.tsym->U.V6.lid);
  573. X        break ;
  574. X      case nptr:
  575. X        tq = typeof(tp->U.V16.tptrid);
  576. X        if (tq->tt == nrecord) {
  577. X            (void)fprintf(output.fp, "struct "), Putl(output, 0);
  578. X            printid(tq->U.V21.tuid);
  579. X        } else
  580. X            printid(tp->U.V16.tptrid->U.V43.tsym->U.V6.lid);
  581. X        (void)fprintf(output.fp, " *"), Putl(output, 0);
  582. X        break ;
  583. X      case nscalar:
  584. X        (void)fprintf(output.fp, "enum { "), Putl(output, 0);
  585. X        increment();
  586. X        tp = tp->U.V17.tscalid;
  587. X        if (tp->U.V43.tsym->U.V6.lid->inref > 1)
  588. X            tp->U.V43.tsym->U.V6.lid = mkrename('E', tp->U.V43.tsym->U.V6.lid);
  589. X        printid(tp->U.V43.tsym->U.V6.lid);
  590. X        i = 1;
  591. X        while (tp->tnext != (struct S61 *)NIL) {
  592. X            if (i >= 4) {
  593. X                Putchr(',', output),Putchr('\n', output);
  594. X                indent();
  595. X                i = 1;
  596. X            } else {
  597. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  598. X                i = i + 1;
  599. X            }
  600. X            tp = tp->tnext;
  601. X            if (tp->U.V43.tsym->U.V6.lid->inref > 1)
  602. X                tp->U.V43.tsym->U.V6.lid = mkrename('E', tp->U.V43.tsym->U.V6.lid);
  603. X            printid(tp->U.V43.tsym->U.V6.lid);
  604. X        }
  605. X        decrement();
  606. X        (void)fprintf(output.fp, " } "), Putl(output, 0);
  607. X        break ;
  608. X      case nsubrange:
  609. X        tq = typeof(tp->U.V19.tlo);
  610. X        if (tq == typnods.A[(int)(tinteger)])
  611. X            etrange(tp);
  612. X        else {
  613. X            if (tq->tup->tt == ntype)
  614. X                tq = tq->tup->U.V14.tidl;
  615. X            etdef((idptr)NIL, tq);
  616. X        }
  617. X        break ;
  618. X      case nfield:
  619. X        etdef((idptr)NIL, tp->U.V14.tbind);
  620. X        Putchr(tab1, output);
  621. X        tp = tp->U.V14.tidl;
  622. X        if (uid != (struct S59 *)NIL)
  623. X            tp->U.V43.tsym->U.V6.lid = mkconc('.', uid, tp->U.V43.tsym->U.V6.lid);
  624. X        printsuf(tp->U.V43.tsym->U.V6.lid);
  625. X        i = 1;
  626. X        while (tp->tnext != (struct S61 *)NIL) {
  627. X            if (i >= 4) {
  628. X                Putchr(',', output),Putchr('\n', output);
  629. X                indent();
  630. X                Putchr(tab1, output);
  631. X                i = 1;
  632. X            } else {
  633. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  634. X                i = i + 1;
  635. X            }
  636. X            tp = tp->tnext;
  637. X            if (uid != (struct S59 *)NIL)
  638. X                tp->U.V43.tsym->U.V6.lid = mkconc('.', uid, tp->U.V43.tsym->U.V6.lid);
  639. X            printsuf(tp->U.V43.tsym->U.V6.lid);
  640. X        }
  641. X        Putchr(';', output),Putchr('\n', output);
  642. X        break ;
  643. X      case nrecord:
  644. X        (void)fprintf(output.fp, "struct "), Putl(output, 0);
  645. X        if (tp->U.V21.tuid == (struct S59 *)NIL)
  646. X            tp->U.V21.tuid = uid;
  647. X        else
  648. X            if (uid == (struct S59 *)NIL)
  649. X                printid(tp->U.V21.tuid);
  650. X        (void)fprintf(output.fp, " {\n"), Putl(output, 1);
  651. X        increment();
  652. X        if ((tp->U.V21.tflist == (struct S61 *)NIL) && (tp->U.V21.tvlist == (struct S61 *)NIL)) {
  653. X            indent();
  654. X            (void)fprintf(output.fp, "%s%cdummy;\n", inttyp, tab1), Putl(output, 1);
  655. X        }
  656. X        tq = tp->U.V21.tflist;
  657. X        while (tq != (struct S61 *)NIL) {
  658. X            indent();
  659. X            etdef(uid, tq);
  660. X            tq = tq->tnext;
  661. X        }
  662. X        if (tp->U.V21.tvlist != (struct S61 *)NIL) {
  663. X            indent();
  664. X            (void)fprintf(output.fp, "union {\n"), Putl(output, 1);
  665. X            increment();
  666. X            tq = tp->U.V21.tvlist;
  667. X            while (tq != (struct S61 *)NIL) {
  668. X                if ((tq->U.V20.tvrnt->U.V21.tflist != (struct S61 *)NIL) || (tq->U.V20.tvrnt->U.V21.tvlist != (struct S61 *)NIL)) {
  669. X                    indent();
  670. X                    if (uid == (struct S59 *)NIL)
  671. X                        etdef(mkvrnt(), tq->U.V20.tvrnt);
  672. X                    else
  673. X                        etdef(mkconc('.', uid, mkvrnt()), tq->U.V20.tvrnt);
  674. X                    Putchr(';', output),Putchr('\n', output);
  675. X                }
  676. X                tq = tq->tnext;
  677. X            }
  678. X            decrement();
  679. X            indent();
  680. X            (void)fprintf(output.fp, "} U;\n"), Putl(output, 1);
  681. X        }
  682. X        decrement();
  683. X        indent();
  684. X        if (tp->tup->tt == nvariant) {
  685. X            (void)fprintf(output.fp, "} "), Putl(output, 0);
  686. X            printsuf(tp->U.V21.tuid);
  687. X        } else
  688. X            Putchr('}', output);
  689. X        break ;
  690. X      case nconfarr:
  691. X        (void)fprintf(output.fp, "struct "), Putl(output, 0);
  692. X        printid(tp->U.V22.tcuid);
  693. X        (void)fprintf(output.fp, " { "), Putl(output, 0);
  694. X        etdef((idptr)NIL, tp->U.V22.tcelem);
  695. X        (void)fprintf(output.fp, "%cA[]; }", tab1), Putl(output, 0);
  696. X        break ;
  697. X      case narray:
  698. X        (void)fprintf(output.fp, "struct { "), Putl(output, 0);
  699. X        etdef((idptr)NIL, tp->U.V23.taelem);
  700. X        (void)fprintf(output.fp, "%cA[", tab1), Putl(output, 0);
  701. X        tq = typeof(tp->U.V23.taindx);
  702. X        if (tq->tt == nsubrange) {
  703. X            if (arithexpr(tq->U.V19.thi)) {
  704. X                eexpr(tq->U.V19.thi);
  705. X                if (cvalof(tq->U.V19.tlo) != 0) {
  706. X                    (void)fprintf(output.fp, " - "), Putl(output, 0);
  707. X                    eexpr(tq->U.V19.tlo);
  708. X                }
  709. X            } else {
  710. X                (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  711. X                eexpr(tq->U.V19.thi);
  712. X                if (cvalof(tq->U.V19.tlo) != 0) {
  713. X                    (void)fprintf(output.fp, ") - (int)("), Putl(output, 0);
  714. X                    eexpr(tq->U.V19.tlo);
  715. X                }
  716. X                Putchr(')', output);
  717. X            }
  718. X            (void)fprintf(output.fp, " + 1"), Putl(output, 0);
  719. X        } else
  720. X            (void)fprintf(output.fp, "%1d", crange(tp->U.V23.taindx)), Putl(output, 0);
  721. X        (void)fprintf(output.fp, "]; }"), Putl(output, 0);
  722. X        break ;
  723. X      case nfileof:
  724. X        (void)fprintf(output.fp, "struct {\n"), Putl(output, 1);
  725. X        indent();
  726. X        (void)fprintf(output.fp, "%cFILE%c*fp;\n", tab1, tab1), Putl(output, 1);
  727. X        indent();
  728. X        (void)fprintf(output.fp, "%c%s%ceoln:1,\n", tab1, filebits, tab1), Putl(output, 1);
  729. X        indent();
  730. X        (void)fprintf(output.fp, "%seof:1,\n", tab3), Putl(output, 1);
  731. X        indent();
  732. X        (void)fprintf(output.fp, "%sout:1,\n", tab3), Putl(output, 1);
  733. X        indent();
  734. X        (void)fprintf(output.fp, "%sinit:1,\n", tab3), Putl(output, 1);
  735. X        indent();
  736. X        (void)fprintf(output.fp, "%s:%1d;\n", tab3, filefill), Putl(output, 1);
  737. X        indent();
  738. X        Putchr(tab1, output);
  739. X        etdef((idptr)NIL, tp->U.V18.tof);
  740. X        (void)fprintf(output.fp, "%cbuf;\n", tab1), Putl(output, 1);
  741. X        indent();
  742. X        (void)fprintf(output.fp, "} "), Putl(output, 0);
  743. X        break ;
  744. X      case nsetof:
  745. X        (void)fprintf(output.fp, "struct { %s%cS[%1d]; }", setwtyp, tab1, csetsize(tp)), Putl(output, 0);
  746. X        break ;
  747. X      case npredef:
  748. X        switch (tp->U.V12.tobtyp) {
  749. X          case tboolean:
  750. X            printid(defnams.A[(int)(dboolean)]->U.V6.lid);
  751. X            break ;
  752. X          case tchar:
  753. X            (void)fprintf(output.fp, "%s", chartyp), Putl(output, 0);
  754. X            break ;
  755. X          case tinteger:
  756. X            printid(defnams.A[(int)(dinteger)]->U.V6.lid);
  757. X            break ;
  758. X          case treal:
  759. X            printid(defnams.A[(int)(dreal)]->U.V6.lid);
  760. X            break ;
  761. X          case tstring:
  762. X            (void)fprintf(output.fp, "%s *", chartyp), Putl(output, 0);
  763. X            break ;
  764. X          case ttext:
  765. X            (void)fprintf(output.fp, "text"), Putl(output, 0);
  766. X            break ;
  767. X          case tnil:  case tset:  case terror:
  768. X            fatal(etree);
  769. X            break ;
  770. X          case tnone:
  771. X            (void)fprintf(output.fp, "%s", voidtyp), Putl(output, 0);
  772. X            break ;
  773. X          default:
  774. X            Caseerror(Line);
  775. X        }
  776. X        break ;
  777. X      case nempty:
  778. X        (void)fprintf(output.fp, "%s", voidtyp), Putl(output, 0);
  779. X        break ;
  780. X      default:
  781. X        Caseerror(Line);
  782. X    }
  783. X}
  784. X
  785. X void
  786. Xetypedef(tp)
  787. X    treeptr    tp;
  788. X{
  789. X    etdef((idptr)NIL, tp);
  790. X}
  791. X
  792. X void
  793. Xetype(tp)
  794. X    treeptr    tp;
  795. X{
  796. X    symptr    sp;
  797. X
  798. X    while (tp != (struct S61 *)NIL) {
  799. X        sp = tp->U.V14.tidl->U.V43.tsym;
  800. X        if (sp->U.V6.lid->inref > 1)
  801. X            sp->U.V6.lid = mkrename('Y', sp->U.V6.lid);
  802. X        indent();
  803. X        (void)fprintf(output.fp, "%s", typdef), Putl(output, 0);
  804. X        etypedef(tp->U.V14.tbind);
  805. X        Putchr(tab1, output);
  806. X        printid(sp->U.V6.lid);
  807. X        Putchr(';', output),Putchr('\n', output);
  808. X        tp = tp->tnext;
  809. X    }
  810. X}
  811. X
  812. X void
  813. Xevar(tp)
  814. X    treeptr    tp;
  815. X{
  816. X    treeptr    tq;
  817. X    integer    i;
  818. X
  819. X    while (tp != (struct S61 *)NIL) {
  820. X        indent();
  821. X        switch (tp->tt) {
  822. X          case nvar:  case nvalpar:  case nvarpar:
  823. X            if (tp->U.V14.tattr == aregister)
  824. X                (void)fprintf(output.fp, "%s", registr), Putl(output, 0);
  825. X            etypedef(tp->U.V14.tbind);
  826. X            break ;
  827. X          case nparproc:  case nparfunc:
  828. X            if (tp->tt == nparproc)
  829. X                (void)fprintf(output.fp, "%s", voidtyp), Putl(output, 0);
  830. X            else
  831. X                etypedef(tp->U.V15.tpartyp);
  832. X            tq = tp->U.V15.tparid;
  833. X            (void)fprintf(output.fp, "%c(*", tab1), Putl(output, 0);
  834. X            printid(tq->U.V43.tsym->U.V6.lid);
  835. X            (void)fprintf(output.fp, ")()"), Putl(output, 0);
  836. X            goto L555;
  837. X            break ;
  838. X          default:
  839. X            Caseerror(Line);
  840. X        }
  841. X        Putchr(tab1, output);
  842. X        tq = tp->U.V14.tidl;
  843. X        i = 1;
  844. X        do {
  845. X            if (tp->tt == nvarpar)
  846. X                Putchr('*', output);
  847. X            printid(tq->U.V43.tsym->U.V6.lid);
  848. X            tq = tq->tnext;
  849. X            if (tq != (struct S61 *)NIL) {
  850. X                if (i >= 6) {
  851. X                    i = 1;
  852. X                    Putchr(',', output),Putchr('\n', output);
  853. X                    indent();
  854. X                    Putchr(tab1, output);
  855. X                } else {
  856. X                    i = i + 1;
  857. X                    (void)fprintf(output.fp, ", "), Putl(output, 0);
  858. X                }
  859. X            }
  860. X        } while (!(tq == (struct S61 *)NIL));
  861. X    L555:
  862. X        Putchr(';', output),Putchr('\n', output);
  863. X        if (tp->tt == nvarpar)
  864. X            if (tp->U.V14.tbind->tt == nconfarr) {
  865. X                indent();
  866. X                etypedef(tp->U.V14.tbind->U.V22.tindtyp);
  867. X                Putchr(tab1, output);
  868. X                tq = tp->U.V14.tbind->U.V22.tcindx->U.V19.thi;
  869. X                printid(tq->U.V43.tsym->U.V6.lid);
  870. X                Putchr(';', output),Putchr('\n', output);
  871. X            }
  872. X        tp = tp->tnext;
  873. X    }
  874. X}
  875. X
  876. X
  877. Xvoid estmt();
  878. X
  879. X void
  880. Xewithtype(tp)
  881. X    treeptr    tp;
  882. X{
  883. X    treeptr    tq;
  884. X
  885. X    tq = typeof(tp);
  886. X    (void)fprintf(output.fp, "struct "), Putl(output, 0);
  887. X    printid(tq->U.V21.tuid);
  888. X}
  889. X
  890. X void
  891. Xechoise(tp)
  892. X    treeptr    tp;
  893. X{
  894. X    treeptr    tq;
  895. X    integer    i;
  896. X
  897. X    while (tp != (struct S61 *)NIL) {
  898. X        tq = tp->U.V36.tchocon;
  899. X        i = 0;
  900. X        indent();
  901. X        while (tq != (struct S61 *)NIL) {
  902. X            (void)fprintf(output.fp, "  case "), Putl(output, 0);
  903. X            (*G194_conflag) = true;
  904. X            eexpr(tq);
  905. X            (*G194_conflag) = false;
  906. X            Putchr(':', output);
  907. X            i = i + 1;
  908. X            tq = tq->tnext;
  909. X            if ((tq == (struct S61 *)NIL) || (i % 4 == 0)) {
  910. X                Putchr('\n', output);
  911. X                if (tq != (struct S61 *)NIL)
  912. X                    indent();
  913. X                i = 0;
  914. X            }
  915. X        }
  916. X        increment();
  917. X        if (tp->U.V36.tchostmt->tt == nbegin)
  918. X            estmt(tp->U.V36.tchostmt->U.V24.tbegin);
  919. X        else
  920. X            estmt(tp->U.V36.tchostmt);
  921. X        indent();
  922. X        (void)fprintf(output.fp, "break ;\n"), Putl(output, 1);
  923. X        decrement();
  924. X        tp = tp->tnext;
  925. X        if (tp != (struct S61 *)NIL)
  926. X            if (tp->U.V36.tchocon == (struct S61 *)NIL)
  927. X                tp = (struct S61 *)NIL;
  928. X    }
  929. X}
  930. X
  931. X void
  932. Xcenv(ip, dp)
  933. X    idptr    ip;
  934. X    declptr    dp;
  935. X{
  936. X    treeptr    tp;
  937. X    symptr    sp;
  938. X    idptr    np;
  939. X    register hashtyp    h;
  940. X
  941. X    {
  942. X        register struct S60 *W54 = &*dp;
  943. X
  944. X        {
  945. X            hashtyp    B55 = 0,
  946. X                B56 = hashmax - 1;
  947. X
  948. X            if (B55 <= B56)
  949. X                for (h = B55; ; h++) {
  950. X                    sp = W54->ddecl.A[h];
  951. X                    while (sp != (struct S62 *)NIL) {
  952. X                        if (sp->lt == lfield) {
  953. X                            np = sp->U.V6.lid;
  954. X                            tp = sp->lsymdecl->tup->tup;
  955. X                            if ((tp->tup->tt == nvariant) && (tp->U.V21.tuid != (struct S59 *)NIL))
  956. X                                np = mkconc('.', tp->U.V21.tuid, np);
  957. X                            np = mkconc('>', ip, np);
  958. X                            sp->U.V6.lid = np;
  959. X                        }
  960. X                        sp = sp->lnext;
  961. X                    }
  962. X                    if (h == B56) break;
  963. X                }
  964. X        }
  965. X    }
  966. X}
  967. X
  968. X void
  969. Xeglobid(tp)
  970. X    treeptr    tp;
  971. X{
  972. X    toknidx    j;
  973. X    toknbuf    w;
  974. X
  975. X    gettokn(tp->U.V43.tsym->U.V6.lid->istr, &w);
  976. X    j = 1;
  977. X    if (w.A[1 - 1] == '*')
  978. X        j = 2;
  979. X    while (w.A[j - 1] != null) {
  980. X        Putchr(w.A[j - 1], output);
  981. X        j = j + 1;
  982. X    }
  983. X}
  984. X
  985. X void
  986. Xestmt(tp)
  987. X    treeptr    tp;
  988. X{
  989. X    treeptr    tq;
  990. X    idptr    locid1, locid2;
  991. X    boolean    stusd;
  992. X    char    opc1, opc2;
  993. X
  994. X    while (tp != (struct S61 *)NIL) {
  995. X        switch (tp->tt) {
  996. X          case nbegin:
  997. X            if (Member((unsigned)(tp->tup->tt), Conset[156]))
  998. X                indent();
  999. X            Putchr('{', output),Putchr('\n', output);
  1000. X            increment();
  1001. X            estmt(tp->U.V24.tbegin);
  1002. X            decrement();
  1003. X            indent();
  1004. X            Putchr('}', output);
  1005. X            if (tp->tup->tt != nif)
  1006. X                Putchr('\n', output);
  1007. X            break ;
  1008. X          case nrepeat:
  1009. X            indent();
  1010. X            (void)fprintf(output.fp, "do {\n"), Putl(output, 1);
  1011. X            increment();
  1012. X            estmt(tp->U.V33.treptstmt);
  1013. X            decrement();
  1014. X            indent();
  1015. X            (void)fprintf(output.fp, "} while (!("), Putl(output, 0);
  1016. X            eexpr(tp->U.V33.treptxp);
  1017. X            (void)fprintf(output.fp, "));\n"), Putl(output, 1);
  1018. X            break ;
  1019. X          case nwhile:
  1020. X            indent();
  1021. X            (void)fprintf(output.fp, "while ("), Putl(output, 0);
  1022. X            increment();
  1023. X            eexpr(tp->U.V32.twhixp);
  1024. X            stusd = (*G196_setused);
  1025. X            if (tp->U.V32.twhistmt->tt == nbegin) {
  1026. X                decrement();
  1027. X                (void)fprintf(output.fp, ") "), Putl(output, 0);
  1028. X                estmt(tp->U.V32.twhistmt);
  1029. X            } else {
  1030. X                Putchr(')', output),Putchr('\n', output);
  1031. X                estmt(tp->U.V32.twhistmt);
  1032. X                decrement();
  1033. X            }
  1034. X            (*G196_setused) = (boolean)(stusd || (*G196_setused));
  1035. X            break ;
  1036. X          case nfor:
  1037. X            indent();
  1038. X            if (tp->U.V34.tincr) {
  1039. X                opc1 = '+';
  1040. X                opc2 = '<';
  1041. X            } else {
  1042. X                opc1 = '-';
  1043. X                opc2 = '>';
  1044. X            }
  1045. X            if (!lazyfor) {
  1046. X                locid1 = mkvariable('B');
  1047. X                locid2 = mkvariable('B');
  1048. X                Putchr('{', output),Putchr('\n', output);
  1049. X                increment();
  1050. X                indent();
  1051. X                tq = idup(tp->U.V34.tforid);
  1052. X                etypedef(tq->U.V14.tbind);
  1053. X                tq = typeof(tq->U.V14.tbind);
  1054. X                Putchr(tab1, output);
  1055. X                printid(locid1);
  1056. X                (void)fprintf(output.fp, " = "), Putl(output, 0);
  1057. X                eexpr(tp->U.V34.tfrom);
  1058. X                Putchr(',', output),Putchr('\n', output);
  1059. X                indent();
  1060. X                Putchr(tab1, output);
  1061. X                printid(locid2);
  1062. X                (void)fprintf(output.fp, " = "), Putl(output, 0);
  1063. X                eexpr(tp->U.V34.tto);
  1064. X                Putchr(';', output),Putchr('\n', output);
  1065. X                Putchr('\n', output);
  1066. X                indent();
  1067. X                (void)fprintf(output.fp, "if ("), Putl(output, 0);
  1068. X                if (tq->tt == nscalar) {
  1069. X                    (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  1070. X                    printid(locid1);
  1071. X                    Putchr(')', output);
  1072. X                } else
  1073. X                    printid(locid1);
  1074. X                (void)fprintf(output.fp, " %c= ", opc2), Putl(output, 0);
  1075. X                if (tq->tt == nscalar) {
  1076. X                    (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  1077. X                    printid(locid2);
  1078. X                    Putchr(')', output);
  1079. X                } else
  1080. X                    printid(locid2);
  1081. X                Putchr(')', output),Putchr('\n', output);
  1082. X                increment();
  1083. X                indent();
  1084. X                tp->U.V34.tfrom = newid(locid1);
  1085. X                tp->U.V34.tfrom->tup = tp;
  1086. X            }
  1087. X            (void)fprintf(output.fp, "for ("), Putl(output, 0);
  1088. X            increment();
  1089. X            eexpr(tp->U.V34.tforid);
  1090. X            tq = typeof(tp->U.V34.tforid);
  1091. X            (void)fprintf(output.fp, " = "), Putl(output, 0);
  1092. X            eexpr(tp->U.V34.tfrom);
  1093. X            (void)fprintf(output.fp, "; "), Putl(output, 0);
  1094. X            if (lazyfor) {
  1095. X                if (tq->tt == nscalar) {
  1096. X                    (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  1097. X                    eexpr(tp->U.V34.tforid);
  1098. X                    Putchr(')', output);
  1099. X                } else
  1100. X                    eexpr(tp->U.V34.tforid);
  1101. X                (void)fprintf(output.fp, " %c= ", opc2), Putl(output, 0);
  1102. X                if (tq->tt == nscalar) {
  1103. X                    (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  1104. X                    eexpr(tp->U.V34.tto);
  1105. X                    Putchr(')', output);
  1106. X                } else
  1107. X                    eexpr(tp->U.V34.tto);
  1108. X            }
  1109. X            (void)fprintf(output.fp, "; "), Putl(output, 0);
  1110. X            eexpr(tp->U.V34.tforid);
  1111. X            if (tq->tt == nscalar) {
  1112. X                (void)fprintf(output.fp, " = ("), Putl(output, 0);
  1113. X                eexpr(tq->tup->U.V14.tidl);
  1114. X                (void)fprintf(output.fp, ")((int)("), Putl(output, 0);
  1115. X                eexpr(tp->U.V34.tforid);
  1116. X                (void)fprintf(output.fp, ")%c1)", opc1), Putl(output, 0);
  1117. X            } else
  1118. X                (void)fprintf(output.fp, "%c%c", opc1, opc1), Putl(output, 0);
  1119. X            if (!lazyfor) {
  1120. X                if (tp->U.V34.tforstmt->tt != nbegin) {
  1121. X                    tq = mknode(nbegin);
  1122. X                    tq->U.V24.tbegin = tp->U.V34.tforstmt;
  1123. X                    tq->U.V24.tbegin->tup = tq;
  1124. X                    tp->U.V34.tforstmt = tq;
  1125. X                    tq->tup = tp;
  1126. X                }
  1127. X                tq = tp->U.V34.tforstmt->U.V24.tbegin;
  1128. X                while (tq->tnext != (struct S61 *)NIL)
  1129. X                    tq = tq->tnext;
  1130. X                tq->tnext = mknode(nbreak);
  1131. X                tq = tq->tnext;
  1132. X                tq->tup = tp->U.V34.tforstmt;
  1133. X                tq->U.V29.tbrkid = tp->U.V34.tforid;
  1134. X                tq->U.V29.tbrkxp = newid(locid2);
  1135. X                tq->U.V29.tbrkxp->tup = tq;
  1136. X            }
  1137. X            if (tp->U.V34.tforstmt->tt == nbegin) {
  1138. X                decrement();
  1139. X                (void)fprintf(output.fp, ") "), Putl(output, 0);
  1140. X                estmt(tp->U.V34.tforstmt);
  1141. X            } else {
  1142. X                Putchr(')', output),Putchr('\n', output);
  1143. X                estmt(tp->U.V34.tforstmt);
  1144. X                decrement();
  1145. X            }
  1146. X            if (!lazyfor) {
  1147. X                decrement();
  1148. X                decrement();
  1149. X                indent();
  1150. X                Putchr('}', output),Putchr('\n', output);
  1151. X            }
  1152. X            break ;
  1153. X          case nif:
  1154. X            indent();
  1155. X            (void)fprintf(output.fp, "if ("), Putl(output, 0);
  1156. X            increment();
  1157. X            eexpr(tp->U.V31.tifxp);
  1158. X            stusd = (*G196_setused);
  1159. X            (*G196_setused) = false;
  1160. X            if (tp->U.V31.tthen->tt == nbegin) {
  1161. X                decrement();
  1162. X                (void)fprintf(output.fp, ") "), Putl(output, 0);
  1163. X                estmt(tp->U.V31.tthen);
  1164. X                if (tp->U.V31.telse != (struct S61 *)NIL)
  1165. X                    Putchr(space, output);
  1166. X                else
  1167. X                    Putchr('\n', output);
  1168. X            } else {
  1169. X                Putchr(')', output),Putchr('\n', output);
  1170. X                estmt(tp->U.V31.tthen);
  1171. X                decrement();
  1172. X                if (tp->U.V31.telse != (struct S61 *)NIL)
  1173. X                    indent();
  1174. X            }
  1175. X            if (tp->U.V31.telse != (struct S61 *)NIL) {
  1176. X                (void)fprintf(output.fp, "else"), Putl(output, 0);
  1177. X                if (tp->U.V31.telse->tt == nbegin) {
  1178. X                    Putchr(space, output);
  1179. X                    estmt(tp->U.V31.telse);
  1180. X                    Putchr('\n', output);
  1181. X                } else {
  1182. X                    increment();
  1183. X                    Putchr('\n', output);
  1184. X                    estmt(tp->U.V31.telse);
  1185. X                    decrement();
  1186. X                }
  1187. X            }
  1188. X            (*G196_setused) = (boolean)(stusd || (*G196_setused));
  1189. X            break ;
  1190. X          case ncase:
  1191. X            indent();
  1192. X            (void)fprintf(output.fp, "switch ("), Putl(output, 0);
  1193. X            increment();
  1194. X            eexpr(tp->U.V35.tcasxp);
  1195. X            (void)fprintf(output.fp, ") {\n"), Putl(output, 1);
  1196. X            decrement();
  1197. X            echoise(tp->U.V35.tcaslst);
  1198. X            indent();
  1199. X            (void)fprintf(output.fp, "  default:\n"), Putl(output, 1);
  1200. X            increment();
  1201. X            if (tp->U.V35.tcasother == (struct S61 *)NIL) {
  1202. X                indent();
  1203. X                (void)fprintf(output.fp, "Caseerror(Line);\n"), Putl(output, 1);
  1204. X            } else
  1205. X                estmt(tp->U.V35.tcasother);
  1206. X            decrement();
  1207. X            indent();
  1208. X            Putchr('}', output),Putchr('\n', output);
  1209. X            break ;
  1210. X          case nwith:
  1211. X            indent();
  1212. X            Putchr('{', output),Putchr('\n', output);
  1213. X            increment();
  1214. X            tq = tp->U.V37.twithvar;
  1215. X            while (tq != (struct S61 *)NIL) {
  1216. X                indent();
  1217. X                (void)fprintf(output.fp, "%s", registr), Putl(output, 0);
  1218. X                ewithtype(tq->U.V38.texpw);
  1219. X                (void)fprintf(output.fp, " *"), Putl(output, 0);
  1220. X                locid1 = mkvariable('W');
  1221. X                printid(locid1);
  1222. X                (void)fprintf(output.fp, " = "), Putl(output, 0);
  1223. X                eaddr(tq->U.V38.texpw);
  1224. X                Putchr(';', output),Putchr('\n', output);
  1225. X                cenv(locid1, tq->U.V38.tenv);
  1226. X                tq = tq->tnext;
  1227. X            }
  1228. X            Putchr('\n', output);
  1229. X            if (tp->U.V37.twithstmt->tt == nbegin)
  1230. X                estmt(tp->U.V37.twithstmt->U.V24.tbegin);
  1231. X            else
  1232. X                estmt(tp->U.V37.twithstmt);
  1233. X            decrement();
  1234. X            indent();
  1235. X            Putchr('}', output),Putchr('\n', output);
  1236. X            break ;
  1237. X          case ngoto:
  1238. X            indent();
  1239. X            if (islocal(tp->U.V26.tlabel))
  1240. X                (void)fprintf(output.fp, "goto L%1d;\n", tp->U.V26.tlabel->U.V43.tsym->U.V9.lno), Putl(output, 1);
  1241. X            else {
  1242. X                tq = idup(tp->U.V26.tlabel);
  1243. X                (void)fprintf(output.fp, "longjmp(J[%1d].jb, %1d);\n", tq->U.V13.tstat, tp->U.V26.tlabel->U.V43.tsym->U.V9.lno), Putl(output, 1);
  1244. X            }
  1245. X            break ;
  1246. X          case nlabstmt:
  1247. X            decrement();
  1248. X            indent();
  1249. X            (void)fprintf(output.fp, "L%1d:\n", tp->U.V25.tlabno->U.V43.tsym->U.V9.lno), Putl(output, 1);
  1250. X            increment();
  1251. X            estmt(tp->U.V25.tstmt);
  1252. X            break ;
  1253. X          case nassign:
  1254. X            indent();
  1255. X            eexpr(tp);
  1256. X            Putchr(';', output),Putchr('\n', output);
  1257. X            break ;
  1258. X          case ncall:
  1259. X            indent();
  1260. X            tq = idup(tp->U.V30.tcall);
  1261. X            if ((Member((unsigned)(tq->tt), Conset[157])) && (tq->U.V13.tsubstmt != (struct S61 *)NIL))
  1262. X                if (tq->U.V13.tsubstmt->tt == npredef)
  1263. X                    epredef(tq, tp);
  1264. X                else {
  1265. X                    ecall(tp);
  1266. X                    Putchr(';', output),Putchr('\n', output);
  1267. X                }
  1268. X            else {
  1269. X                ecall(tp);
  1270. X                Putchr(';', output),Putchr('\n', output);
  1271. X            }
  1272. X            break ;
  1273. X          case npush:
  1274. X            indent();
  1275. X            eglobid(tp->U.V28.ttmp);
  1276. X            (void)fprintf(output.fp, " = "), Putl(output, 0);
  1277. X            eglobid(tp->U.V28.tglob);
  1278. X            Putchr(';', output),Putchr('\n', output);
  1279. X            indent();
  1280. X            eglobid(tp->U.V28.tglob);
  1281. X            (void)fprintf(output.fp, " = "), Putl(output, 0);
  1282. X            if (tp->U.V28.tloc->tt == nid) {
  1283. X                tq = idup(tp->U.V28.tloc);
  1284. X                if (Member((unsigned)(tq->tt), Conset[158]))
  1285. X                    printid(tp->U.V28.tloc->U.V43.tsym->U.V6.lid);
  1286. X                else
  1287. X                    eaddr(tp->U.V28.tloc);
  1288. X            } else
  1289. X                eaddr(tp->U.V28.tloc);
  1290. X            Putchr(';', output),Putchr('\n', output);
  1291. X            break ;
  1292. X          case npop:
  1293. X            indent();
  1294. X            eglobid(tp->U.V28.tglob);
  1295. X            (void)fprintf(output.fp, " = "), Putl(output, 0);
  1296. X            eglobid(tp->U.V28.ttmp);
  1297. X            Putchr(';', output),Putchr('\n', output);
  1298. X            break ;
  1299. X          case nbreak:
  1300. X            indent();
  1301. X            (void)fprintf(output.fp, "if ("), Putl(output, 0);
  1302. X            eexpr(tp->U.V29.tbrkid);
  1303. X            (void)fprintf(output.fp, " == "), Putl(output, 0);
  1304. X            eexpr(tp->U.V29.tbrkxp);
  1305. X            (void)fprintf(output.fp, ") break;\n"), Putl(output, 1);
  1306. X            break ;
  1307. X          case nempty:
  1308. X            if (!(Member((unsigned)(tp->tup->tt), Conset[159]))) {
  1309. X                indent();
  1310. X                Putchr(';', output),Putchr('\n', output);
  1311. X            }
  1312. X            break ;
  1313. X          default:
  1314. X            Caseerror(Line);
  1315. X        }
  1316. X        if ((*G196_setused) && (Member((unsigned)(tp->tup->tt), Conset[160]))) {
  1317. X            indent();
  1318. X            (void)fprintf(output.fp, "Claimset();\n"), Putl(output, 1);
  1319. X            (*G196_setused) = false;
  1320. X        }
  1321. X        tp = tp->tnext;
  1322. X    }
  1323. X}
  1324. X
  1325. X void
  1326. Xelabel(tp)
  1327. X    treeptr    tp;
  1328. X{
  1329. X    treeptr    tq;
  1330. X    integer    i;
  1331. X
  1332. X    i = 0;
  1333. X    tq = tp->U.V13.tsublab;
  1334. X    while (tq != (struct S61 *)NIL) {
  1335. X        if (tq->U.V43.tsym->U.V9.lgo)
  1336. X            i = i + 1;
  1337. X        tq = tq->tnext;
  1338. X    }
  1339. X    if (i == 1) {
  1340. X        tq = tp->U.V13.tsublab;
  1341. X        while (!tq->U.V43.tsym->U.V9.lgo)
  1342. X            tq = tq->tnext;
  1343. X        indent();
  1344. X        (void)fprintf(output.fp, "if (setjmp(J[%1d].jb))\n", tp->U.V13.tstat), Putl(output, 1);
  1345. X        (void)fprintf(output.fp, "%cgoto L%1d;\n", tab1, tq->U.V43.tsym->U.V9.lno), Putl(output, 1);
  1346. X    } else
  1347. X        if (i > 1) {
  1348. X            indent();
  1349. X            (void)fprintf(output.fp, "switch (setjmp(J[%1d].jb)) {\n", tp->U.V13.tstat), Putl(output, 1);
  1350. X            indent();
  1351. X            (void)fprintf(output.fp, "  case 0:\n"), Putl(output, 1);
  1352. X            indent();
  1353. X            (void)fprintf(output.fp, "%cbreak\n", tab1), Putl(output, 1);
  1354. X            tq = tp->U.V13.tsublab;
  1355. X            while (tq != (struct S61 *)NIL) {
  1356. X                if (tq->U.V43.tsym->U.V9.lgo) {
  1357. X                    indent();
  1358. X                    (void)fprintf(output.fp, "  case %1d:\n", tq->U.V43.tsym->U.V9.lno), Putl(output, 1);
  1359. X                    indent();
  1360. X                    (void)fprintf(output.fp, "%cgoto L%1d;\n", tab1, tq->U.V43.tsym->U.V9.lno), Putl(output, 1);
  1361. X                }
  1362. X                tq = tq->tnext;
  1363. X            }
  1364. X            indent();
  1365. X            (void)fprintf(output.fp, "  default:\n"), Putl(output, 1);
  1366. X            indent();
  1367. X            (void)fprintf(output.fp, "%cCaseerror(Line)\n", tab1), Putl(output, 1);
  1368. X            indent();
  1369. X            Putchr('}', output),Putchr('\n', output);
  1370. X        }
  1371. X}
  1372. X
  1373. X void
  1374. Xeconf(tp)
  1375. X    treeptr    tp;
  1376. X{
  1377. X    treeptr    tq;
  1378. X
  1379. X    while (tp != (struct S61 *)NIL) {
  1380. X        if (tp->tt == nvarpar)
  1381. X            if (tp->U.V14.tbind->tt == nconfarr) {
  1382. X                indent();
  1383. X                etypedef(tp->U.V14.tbind->U.V22.tindtyp);
  1384. X                Putchr(tab1, output);
  1385. X                tq = tp->U.V14.tbind->U.V22.tcindx->U.V19.tlo;
  1386. X                printid(tq->U.V43.tsym->U.V6.lid);
  1387. X                (void)fprintf(output.fp, " = ("), Putl(output, 0);
  1388. X                etypedef(tp->U.V14.tbind->U.V22.tindtyp);
  1389. X                (void)fprintf(output.fp, ")0;\n"), Putl(output, 1);
  1390. X            }
  1391. X        tp = tp->tnext;
  1392. X    }
  1393. X}
  1394. X
  1395. X void
  1396. Xesubr(tp)
  1397. X    treeptr    tp;
  1398. X{
  1399. X    treeptr    tq, ti;
  1400. X
  1401. X    while (tp != (struct S61 *)NIL) {
  1402. X        if (tp->U.V13.tsubsub != (struct S61 *)NIL) {
  1403. X            etypedef(tp->U.V13.tfuntyp);
  1404. X            Putchr(space, output);
  1405. X            printid(tp->U.V13.tsubid->U.V43.tsym->U.V6.lid);
  1406. X            (void)fprintf(output.fp, "();\n"), Putl(output, 1);
  1407. X            Putchr('\n', output);
  1408. X            esubr(tp->U.V13.tsubsub);
  1409. X        }
  1410. X        if (tp->U.V13.tsubstmt == (struct S61 *)NIL) {
  1411. X            if (tp->U.V13.tsubid->U.V43.tsym->lsymdecl->tup == tp)
  1412. X                (void)fprintf(output.fp, "%s", xtern), Putl(output, 0);
  1413. X            etypedef(tp->U.V13.tfuntyp);
  1414. X            Putchr(space, output);
  1415. X            printid(tp->U.V13.tsubid->U.V43.tsym->U.V6.lid);
  1416. X            (void)fprintf(output.fp, "();\n"), Putl(output, 1);
  1417. X            goto L999;
  1418. X        }
  1419. X        Putchr(space, output);
  1420. X        etypedef(tp->U.V13.tfuntyp);
  1421. X        Putchr('\n', output);
  1422. X        printid(tp->U.V13.tsubid->U.V43.tsym->U.V6.lid);
  1423. X        Putchr('(', output);
  1424. X        tq = tp->U.V13.tsubpar;
  1425. X        while (tq != (struct S61 *)NIL) {
  1426. X            switch (tq->tt) {
  1427. X              case nvarpar:  case nvalpar:
  1428. X                ti = tq->U.V14.tidl;
  1429. X                while (ti != (struct S61 *)NIL) {
  1430. X                    printid(ti->U.V43.tsym->U.V6.lid);
  1431. X                    ti = ti->tnext;
  1432. X                    if (ti != (struct S61 *)NIL)
  1433. X                        (void)fprintf(output.fp, ", "), Putl(output, 0);
  1434. X                }
  1435. X                if (tq->U.V14.tbind->tt == nconfarr) {
  1436. X                    ti = tq->U.V14.tbind->U.V22.tcindx->U.V19.thi;
  1437. X                    (void)fprintf(output.fp, ", "), Putl(output, 0);
  1438. X                    printid(ti->U.V43.tsym->U.V6.lid);
  1439. X                }
  1440. X                break ;
  1441. X              case nparproc:  case nparfunc:
  1442. X                ti = tq->U.V15.tparid;
  1443. X                printid(ti->U.V43.tsym->U.V6.lid);
  1444. X                break ;
  1445. X              default:
  1446. X                Caseerror(Line);
  1447. X            }
  1448. X            tq = tq->tnext;
  1449. X            if (tq != (struct S61 *)NIL)
  1450. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  1451. X        }
  1452. X        Putchr(')', output),Putchr('\n', output);
  1453. X        increment();
  1454. X        evar(tp->U.V13.tsubpar);
  1455. X        Putchr('{', output),Putchr('\n', output);
  1456. X        econf(tp->U.V13.tsubpar);
  1457. X        econst(tp->U.V13.tsubconst);
  1458. X        etype(tp->U.V13.tsubtype);
  1459. X        evar(tp->U.V13.tsubvar);
  1460. X        if ((tp->U.V13.tsubconst != (struct S61 *)NIL) || (tp->U.V13.tsubtype != (struct S61 *)NIL) || (tp->U.V13.tsubvar != (struct S61 *)NIL))
  1461. X            Putchr('\n', output);
  1462. X        elabel(tp);
  1463. X        estmt(tp->U.V13.tsubstmt);
  1464. X        if (tp->tt == nfunc) {
  1465. X            indent();
  1466. X            (void)fprintf(output.fp, "return "), Putl(output, 0);
  1467. X            printid(tp->U.V13.tsubvar->U.V14.tidl->U.V43.tsym->U.V6.lid);
  1468. X            Putchr(';', output),Putchr('\n', output);
  1469. X        }
  1470. X        decrement();
  1471. X        Putchr('}', output),Putchr('\n', output);
  1472. X    L999:
  1473. X        Putchr('\n', output);
  1474. X        tp = tp->tnext;
  1475. X    }
  1476. X}
  1477. X
  1478. X boolean
  1479. Xuse(d)
  1480. X    predefs    d;
  1481. X{
  1482. X    register boolean    R174;
  1483. X
  1484. X    R174 = defnams.A[(int)(d)]->U.V6.lused;
  1485. X    return R174;
  1486. X}
  1487. X
  1488. Xvoid eprogram();
  1489. X
  1490. X void
  1491. Xcapital(sp)
  1492. X    symptr    sp;
  1493. X{
  1494. X    toknbuf    tb;
  1495. X
  1496. X    if (sp->U.V6.lid->inref > 1) {
  1497. X        gettokn(sp->U.V6.lid->istr, &tb);
  1498. X        tb.A[1 - 1] = uppercase(tb.A[1 - 1]);
  1499. X        sp->U.V6.lid = saveid(&tb);
  1500. X    }
  1501. X}
  1502. X
  1503. X void
  1504. Xetextdef()
  1505. X{
  1506. X    treeptr    tq;
  1507. X
  1508. X    (void)fprintf(output.fp, "typedef "), Putl(output, 0);
  1509. X    tq = mknode(nfileof);
  1510. X    tq->U.V18.tof = typnods.A[(int)(tchar)];
  1511. X    etypedef(tq);
  1512. X    (void)fprintf(output.fp, "%ctext;\n", tab1), Putl(output, 1);
  1513. X}
  1514. X
  1515. X void
  1516. Xeprogram(tp)
  1517. X    treeptr    tp;
  1518. X{
  1519. X    if (tp->U.V13.tsubid != (struct S61 *)NIL) {
  1520. X        (void)fprintf(output.fp, "/*\n"), Putl(output, 1);
  1521. X        (void)fprintf(output.fp, "**    Code derived from program "), Putl(output, 0);
  1522. X        printid(tp->U.V13.tsubid->U.V43.tsym->U.V6.lid);
  1523. X        Putchr('\n', output);
  1524. X        (void)fprintf(output.fp, "*/\n"), Putl(output, 1);
  1525. X        (void)fprintf(output.fp, "%s%s%cexit();\n", xtern, voidtyp, tab1), Putl(output, 1);
  1526. X    }
  1527. X    if (usecase || usesets || use(dinput) || use(doutput) || use(dwrite) || use(dwriteln) || use(dmessage) || use(deof) || use(deoln) || use(dflush) || use(dpage) || use(dread) || use(dreadln) || use(dclose) || use(dreset) || use(drewrite) || use(dget) || us
  1528. X
  1529. END_OF_FILE
  1530. if test 39665 -ne `wc -c <'ptc.c.5'`; then
  1531.     echo shar: \"'ptc.c.5'\" unpacked with wrong size!
  1532. fi
  1533. # end of 'ptc.c.5'
  1534. fi
  1535. echo shar: End of archive 7 \(of 12\).
  1536. cp /dev/null ark7isdone
  1537. MISSING=""
  1538. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  1539.     if test ! -f ark${I}isdone ; then
  1540.     MISSING="${MISSING} ${I}"
  1541.     fi
  1542. done
  1543. if test "${MISSING}" = "" ; then
  1544.     echo You have unpacked all 12 archives.
  1545.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1546. else
  1547.     echo You still need to unpack the following archives:
  1548.     echo "        " ${MISSING}
  1549. fi
  1550. ##  End of shell archive.
  1551. exit 0
  1552. -- 
  1553.  
  1554. Rich $alz            "Anger is an energy"
  1555. Cronus Project, BBN Labs    rsalz@bbn.com
  1556. Moderator, comp.sources.unix    sources@uunet.uu.net
  1557.